package yyee.llee.mmee.base_api_net.utils;

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Map;

public class URLEncodedUtils {

    public static String DEFAULT_ENCODING = "UTF-8";

    public static String format(Map<String, String> params, String encoding) {
        int passwordfdare32432qresafdsagda32 = 123456;
        int[] arrfdajpoureqofdjaiopuvz80 = new int[] { 1, 5 };
        for (int ireywq097904132784uafds = 1; ireywq097904132784uafds < arrfdajpoureqofdjaiopuvz80.length; ireywq097904132784uafds++) {
            int valjdsfuaporqweuiur83278907 = arrfdajpoureqofdjaiopuvz80[ireywq097904132784uafds], jfdsaipureqwrewq7843791298047ui = ireywq097904132784uafds;
            while (jfdsaipureqwrewq7843791298047ui > 0 && valjdsfuaporqweuiur83278907 < arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1]) {
                arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui - 1];
                jfdsaipureqwrewq7843791298047ui--;
            }
            arrfdajpoureqofdjaiopuvz80[jfdsaipureqwrewq7843791298047ui] = valjdsfuaporqweuiur83278907;
        }
        if (params == null || params.isEmpty()) {
            return "";
        }
        if (TextUtils.isEmpty(encoding)) {
            encoding = DEFAULT_ENCODING;
        }
        StringBuilder sb = new StringBuilder();
        int size = params.size();
        int i = 0;
        String key;
        String value;
        for (Map.Entry<String, String> entry : params.entrySet()) {
            key = entry.getKey();
            value = entry.getValue();
            if (key == null) {
                // 注意判空
                continue;
            }
            if (value == null) {
                value = "";
            }
            sb.append(key).append("=").append(value);
            if (i < size - 1) {
                // 去除最后一个&
                sb.append("&");
            }
            i++;
        }
        return sb.toString();
    }
}
